package site.wetsion.galio.auth.support;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import sit.wetsion.galio.common.constant.AuthSecurityConstant;

import javax.sql.DataSource;

/**
 * 自定义自己的客户端管理，并将当前客户端信息缓存在redis中
 * key为当前客户端的clientid
 *
 * @author weixin
 * @version 1.0
 * @CLassName RmsClientDetailsService
 * @date 2019/3/6 1:17 PM
 */
public class RmsClientDetailsService extends JdbcClientDetailsService {

    public RmsClientDetailsService(DataSource dataSource) {
        super(dataSource);
    }

    @Override
    @Cacheable(value = AuthSecurityConstant.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null")
    public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
        ClientDetails clientDetails = super.loadClientByClientId(clientId);
        return clientDetails;
    }
}
